<template>
  <div id="app">
    <nav class="navbar">
      <div class="container">
        <router-link to="/" class="logo">智能健康系统</router-link>
        <div class="nav-links">
          <div class="nav-dropdown">
            <span class="nav-group-title">问卷管理</span>
            <div class="dropdown-content">
              <router-link to="/list" class="nav-link">问卷列表</router-link>
              <router-link to="/create" class="nav-link">创建问卷</router-link>
            </div>
          </div>
          
          <div class="nav-dropdown">
            <span class="nav-group-title">文章管理</span>
            <div class="dropdown-content">
              <router-link to="/article/list" class="nav-link">文章列表</router-link>
              <router-link to="/article/create" class="nav-link">创建文章</router-link>
            </div>
          </div>
        </div>
        
        <button class="mobile-menu-btn" @click="toggleMenu">
          <span></span>
          <span></span>
          <span></span>
        </button>
      </div>
      
      <!-- 移动端菜单 -->
      <div class="mobile-menu" :class="{ 'active': mobileMenuOpen }">
        <div class="mobile-menu-header">
          <span>导航菜单</span>
          <button class="close-menu" @click="toggleMenu">&times;</button>
        </div>
        <div class="mobile-menu-group">
          <div class="mobile-group-title">问卷管理</div>
          <router-link to="/list" class="mobile-nav-link" @click="closeMenu">问卷列表</router-link>
          <router-link to="/create" class="mobile-nav-link" @click="closeMenu">创建问卷</router-link>
        </div>
        <div class="mobile-menu-group">
          <div class="mobile-group-title">文章管理</div>
          <router-link to="/article/list" class="mobile-nav-link" @click="closeMenu">文章列表</router-link>
          <router-link to="/article/create" class="mobile-nav-link" @click="closeMenu">创建文章</router-link>
        </div>
      </div>
    </nav>
    
    <div class="container main-content">
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </div>
    
    <footer class="footer">
      <div class="container">
        <div class="footer-content">
          <div class="footer-section">
            <h3>智能健康系统</h3>
            <p>提供问卷调查、健康文章和睡眠记录等综合健康服务</p>
          </div>
          <div class="footer-section">
            <h3>快速链接</h3>
            <router-link to="/" class="footer-link">首页</router-link>
            <router-link to="/list" class="footer-link">问卷列表</router-link>
            <router-link to="/article/list" class="footer-link">文章列表</router-link>
          </div>
          <div class="footer-section">
            <h3>联系我们</h3>
            <p>邮箱: support@example.com</p>
            <p>电话: 123-456-7890</p>
          </div>
        </div>
        <div class="copyright">
          <p>&copy; {{ new Date().getFullYear() }} 智能健康系统 - 版权所有</p>
        </div>
      </div>
    </footer>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      mobileMenuOpen: false
    }
  },
  methods: {
    toggleMenu() {
      this.mobileMenuOpen = !this.mobileMenuOpen;
      if (this.mobileMenuOpen) {
        document.body.style.overflow = 'hidden'; // 防止背景滚动
      } else {
        document.body.style.overflow = ''; // 恢复滚动
      }
    },
    closeMenu() {
      this.mobileMenuOpen = false;
      document.body.style.overflow = '';
    }
  },
  watch: {
    '$route'() {
      // 路由变化时关闭移动菜单
      this.mobileMenuOpen = false;
      document.body.style.overflow = '';
    }
  }
}
</script>

<style>
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f8f9fa;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
}

.navbar {
  background-color: #4CAF50;
  color: white;
  padding: 15px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.navbar .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: bold;
  color: white;
  text-decoration: none;
}

.nav-links {
  display: flex;
  gap: 30px;
}

.nav-dropdown {
  position: relative;
  padding: 10px 0;
}

.nav-group-title {
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 4px;
  transition: background-color 0.3s;
  font-weight: 500;
}

.nav-dropdown:hover .nav-group-title {
  background-color: rgba(255,255,255,0.2);
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  z-index: 1;
  border-radius: 4px;
  margin-top: 10px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
}

.nav-dropdown:hover .dropdown-content {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.nav-link {
  color: #333;
  text-decoration: none;
  display: block;
  padding: 10px 15px;
  transition: background-color 0.3s;
}

.nav-link:hover {
  background-color: #f5f5f5;
}

.router-link-active.nav-link {
  background-color: #eef5ee;
  color: #4CAF50;
}

.mobile-menu-btn {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  height: 20px;
  background: transparent;
  border: none;
  cursor: pointer;
}

.mobile-menu-btn span {
  display: block;
  width: 25px;
  height: 3px;
  background-color: white;
  border-radius: 2px;
}

.mobile-menu {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: white;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.3s ease-in-out;
  overflow-y: auto;
}

.mobile-menu.active {
  transform: translateX(0);
}

.mobile-menu-header {
  padding: 15px;
  background-color: #4CAF50;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.close-menu {
  background: transparent;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}

.mobile-menu-group {
  padding: 15px;
  border-bottom: 1px solid #eee;
}

.mobile-group-title {
  font-weight: bold;
  color: #4CAF50;
  margin-bottom: 10px;
}

.mobile-nav-link {
  display: block;
  padding: 12px 15px;
  color: #333;
  text-decoration: none;
  border-bottom: 1px solid #f5f5f5;
}

.mobile-nav-link:hover {
  background-color: #f5f5f5;
}

.main-content {
  min-height: calc(100vh - 62px - 250px); /* 视口高度减去导航栏和页脚的高度 */
  padding: 20px 0 40px;
}

.footer {
  background-color: #333;
  color: #f5f5f5;
  padding: 40px 0 20px;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 30px;
  margin-bottom: 30px;
}

.footer-section {
  flex: 1;
  min-width: 250px;
}

.footer-section h3 {
  color: white;
  margin-bottom: 15px;
  font-size: 1.2rem;
}

.footer-link {
  display: block;
  color: #b0b0b0;
  text-decoration: none;
  margin-bottom: 8px;
  transition: color 0.3s;
}

.footer-link:hover {
  color: white;
}

.copyright {
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #444;
  color: #777;
  font-size: 0.9rem;
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-links {
    display: none;
  }
  
  .mobile-menu-btn {
    display: flex;
  }
  
  .mobile-menu {
    display: block;
  }
  
  .footer-content {
    flex-direction: column;
    gap: 25px;
  }
  
  .footer-section {
    min-width: auto;
  }
}
</style>